#include <vector>
#include <iostream>
using namespace std;

class Solution {
public:
    vector<int> productExceptSelf(vector<int>& nums) {
        vector<int> ans(nums.size(), 1);
        int left = 0, right = nums.size() - 1;
        int lp = 1, rp = 1;

        while (left < nums.size() && right >= 0) {
            ans[left] *= lp;
            ans[right] *= rp;

            lp *= nums[left++];
            rp *= nums[right--];
        }

        return ans;
    }
};

// 打印 vector 的辅助函数
void printVector(const vector<int>& v) {
    cout << "[";
    for (int i = 0; i < v.size(); ++i) {
        cout << v[i];
        if (i != v.size() - 1) cout << ", ";
    }
    cout << "]" << endl;
}

int main() {
    Solution sol;

    // 测试用例 1：正常输入
    vector<int> nums1 = {1,2,3,4};
    cout << "Test Case 1: ";
    printVector(sol.productExceptSelf(nums1)); // [24, 12, 8, 6]

    return 0;
}